﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WikcLib.Generate
{
    public class RandomCharacters
    {
        private Random rd = new Random();

        /// <summary>
        /// 常用验证码内容
        /// </summary>
        private char[] arrConstant = 
                {  '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 
                        'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
                };


        /// <summary>
        /// 获取验证码
        /// </summary>
        /// <param name="Length">验证码长度</param>
        /// <returns></returns>
        public string GenerateRandom(int Length)
        {
            System.Text.StringBuilder newRandom = new System.Text.StringBuilder();
            int chrCount = arrConstant.Length;
            string ch = "";
            for (int i = 0; i < Length; i++)
            {
                ch = arrConstant[rd.Next(chrCount)].ToString();
                newRandom.Append(ch);
            }
            return newRandom.ToString();
        } 
    }
}
